package com.das.mechanic_base.adapter.record;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.bean.main.HomeColorBean;

import java.util.ArrayList;
import java.util.List;

public class X3DateAdapter extends RecyclerView.Adapter<X3DateAdapter.DateHolder> {

    private List<HomeColorBean> mList;

    private Context mContext;

    public X3DateAdapter(Context mContext) {
        this.mContext = mContext;
        this.mList = new ArrayList<>();
    }

    public void changeData(List<HomeColorBean> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public DateHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new DateHolder(LayoutInflater.from(mContext).inflate(R.layout.x3_date_record_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull DateHolder holder, int position) {
        holder.tv_date.setText(mList.get(position).getLabel());
        holder.itemView.setOnClickListener(v -> {
            if (iOnClickSelect != null) {
                iOnClickSelect.iOnClickSelectDate(mList.get(position));
            }
        });
    }

    IOnClickSelect iOnClickSelect;

    public void setiOnClickSelect(IOnClickSelect iOnClickSelect) {
        this.iOnClickSelect = iOnClickSelect;
    }

    public interface IOnClickSelect {
        void iOnClickSelectDate(HomeColorBean colorBean);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class DateHolder extends RecyclerView.ViewHolder {
        TextView tv_date;
        public DateHolder(@NonNull View itemView) {
            super(itemView);
            tv_date = itemView.findViewById(R.id.tv_date);
        }
    }
}
